package net.NingXiaRuiTai.ShortChain.config;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import static java.lang.Math.abs;

@Component
public class ShardingDBConfig {
    private static final List<String> dbPrefixList= new ArrayList<>();
    static {
        dbPrefixList.add("0");
        dbPrefixList.add("1");
        dbPrefixList.add("a");
    }
//    private static Random random = new Random();

    /**
     * 随机获取一个库
     * @return
     */
    public static  String getRandomDBPrefix(String code){
        int index=abs(code.hashCode())%dbPrefixList.size();


//        int index = random.nextInt(dbPrefixList.size());
        return dbPrefixList.get(index);
    }
}
